package me.ereach.oop;

public class Triangle {
    // 借助Point类构建我们三角形的三个定点
    private Point a;
    private Point b;
    private Point c;

    // 构造函数
    public Triangle(Point a, Point b, Point c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    // getters & setters
    public Point getA() {
        return a;
    }

    public void setA(Point a) {
        this.a = a;
    }

    public Point getB() {
        return b;
    }

    public void setB(Point b) {
        this.b = b;
    }

    public Point getC() {
        return c;
    }

    public void setC(Point c) {
        this.c = c;
    }

    // 重写父类toString方法
    @Override
    public String toString() {
        return "Triangle{" +
                "a=" + a +
                ", b=" + b +
                ", c=" + c +
                '}';
    }

    // 计算三角形周长
    public double getPerimeter() {
        return b.getDistance(c) + a.getDistance(c) + a.getDistance(b);
    }

    // 计算三角形面积
    public double getArea() {
        double p = getPerimeter() / 2;
        double la = b.getDistance(c);
        double lb = a.getDistance(c);
        double lc = a.getDistance(b);

        return Math.sqrt(p * (p - la) * (p - lb) * (p - lc));
    }
}
